//
//  WelcomeViewController.m
//  LinXiaoNao
//
//  Created by 陈堂 on 15/8/31.
//  Copyright (c) 2015年 陈堂. All rights reserved.
//

#import "WelcomeViewController.h"
#import "loginViewController.h"
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
@interface WelcomeViewController ()

@end

@implementation WelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@"" forKey:@"loginName"];
    [userDefaults setObject:@"" forKey:@"passWord"];
    
//    滑动视图
    _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _scrollView.delegate=self;
    _scrollView.pagingEnabled=YES;
    _scrollView.bounces=NO;
    _scrollView.contentSize=CGSizeMake(ScreenWidth*3, 480);
    NSArray*imgArray=[[NSArray alloc]initWithObjects:@"空中课堂-(ios)(1).jpg",@"空中课堂-(ios2)(1).jpg",@"空中课堂-(ios3)(2).jpg", nil];
    for (int i=0; i<imgArray.count; i++)
    {
        UIImageView *pic=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i,0 , ScreenWidth, ScreenHeight)];
        pic.image=[UIImage imageNamed:imgArray[i]];
        [_scrollView addSubview:pic];
        if (i==2) {
            UIButton*goToButton=[UIButton buttonWithType:UIButtonTypeCustom];
            if (ScreenWidth==320) {
                goToButton.center=CGPointMake(ScreenWidth*2+ScreenWidth/2, ScreenHeight-55);
                goToButton.bounds=CGRectMake(0, 0, ScreenWidth-150, 30);
            }
            else
            {
                goToButton.center=CGPointMake(ScreenWidth*2+ScreenWidth/2, ScreenHeight-70);
                goToButton.bounds=CGRectMake(0, 0, ScreenWidth-150, 50);
            }
            [goToButton setBackgroundImage:[UIImage imageNamed:@"矩形-1"] forState:UIControlStateNormal];
            if (self.viewTagQu==2012) {
                [goToButton setTitle:@"结束观看" forState:UIControlStateNormal];
            }
            else
            {
                [goToButton setTitle:@"欢迎进入" forState:UIControlStateNormal];
            }
            
            [goToButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            goToButton.titleLabel.font=[UIFont systemFontOfSize:15];
            [goToButton addTarget:self action:@selector(Login) forControlEvents:UIControlEventTouchUpInside];
            [_scrollView addSubview:goToButton];
        }
    }
    [self.view addSubview:_scrollView];
    
    _pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight-30, ScreenWidth, 20)];
    _pageControl.numberOfPages=3;
    _pageControl.pageIndicatorTintColor=[UIColor grayColor];
    _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    [_pageControl addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_pageControl];
    
}
-(void)changeValue:(UIPageControl*)pageControl
{
    NSLog(@"-------");
    NSLog(@"------%d",(int)pageControl.currentPage);
    //    改变scroll的显示图片
    [_scrollView setContentOffset:CGPointMake(pageControl.currentPage*ScreenWidth, 0)];
    
   
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //    在结束的时候设置pagecontrol的分页
    NSLog(@"----视图已经结束减速－－－－");
    _pageControl.currentPage = scrollView.contentOffset.x/ScreenWidth;
//    if (_pageControl.currentPage==2)
//    {
//        
//    }
}

#pragma mark -- 登录界面
-(void)Login
{
    if (self.viewTagQu==2012) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[loginViewController new]];
        [self presentViewController:nav animated:YES completion:NULL];
    }
    

    
}

/**
 *  以下两个方法用来隐藏状态栏
 */
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

@end
